<template>
  <div>
    <div>
      <el-col :span="24">
        <el-row style="border-bottom: 1px solid #eee">
          <el-col :span="5">
            <div
              style="
                font-size: 14px;
                text-align: left;
                margin-top: 0px;
                margin-bottom: 0px;
                padding-left: 0px;
                margin-left: 5px;
                padding-bottom: 5px;
                padding-top: 10px;
              "
            ></div>
          </el-col>
          <el-col :span="19">
            <div
              style="
                font-size: 13px;
                text-align: right;
                margin-top: -10px;
                margin-bottom: 0px;
                padding-left: -20px;
                margin-left: -10px;
                padding-bottom: 5px;
                padding-top: 10px;
              "
            >
              <span class="tianwai">
                <span>数据起始日期:</span>
                <el-date-picker
                  style="
                    width: 100px;
                    text-align: center;
                    padding-left: 5px;
                    margin-right: 5px;
                  "
                  v-model="queryBeginDate"
                  class="dataInputer"
                  :clearable="false"
                  type="date"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  @change="queryDataArray"
                />
              </span>
              <span class="tianwai">
                <span>结束日期:</span>
                <el-date-picker
                  style="
                    width: 100px;
                    text-align: center;
                    padding-left: 5px;
                    margin-right: 5px;
                  "
                  v-model="queryEndDate"
                  class="dataInputer"
                  :clearable="false"
                  type="date"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                  @change="queryDataArray"
                />
              </span>
              <el-button
                :loading="queryLoading"
                type="primary"
                size="small"
                @click="queryDataArray"
                class="tianwai"
              >查询</el-button
              >
              <el-button
                type="primary"
                size="small"
                @click="printAllButtonClick"
                :loading="loading"
              >打印</el-button
              >
            </div>
          </el-col>
        </el-row>
        <el-row> </el-row>

        <el-row>
          <el-table
            ref="mainTable"
            :data="dataArray"
            @row-dblclick="rowDbClick"
            :cell-class-name="cellClassName"
            :stripe="true"
            style="width: 100%"
            :row-class-name="tableRowClassName"
            :header-cell-style="{
              background: '#F5F7FA',
              color: '#606266',
            }"
            :cell-style="cellStyle"
            height="600"
          >
            <el-table-column label="操作" width="100" align="center" fixed>
              <template slot-scope="scope">
                <el-button
                  v-if="editIndex != scope.$index && scope.row.id"
                  size="medium"
                  type="text"
                  icon="el-icon-delete"
                  @click="deleteButtonClick(scope.$index, scope.row)"
                  style="color: black"
                ></el-button>
                <el-button
                  v-if="editIndex != scope.$index && !scope.row.flag"
                  size="medium"
                  type="text"
                  icon="el-icon-edit"
                  @click="editButtonClick(scope.$index, $event, scope)"
                  style="color: black"
                ></el-button>
                <el-button
                  v-if="editIndex == scope.$index"
                  size="medium"
                  type="text"
                  icon="el-icon-back"
                  @click="reverseButtonClick(scope.$index)"
                  style="color: green"
                ></el-button>
                <el-button
                  v-if="editIndex == scope.$index"
                  size="medium"
                  type="text"
                  icon="el-icon-check"
                  @click="saveButtonClick(scope, scope.$index)"
                  style="color: blue"
                ></el-button>
              </template>
            </el-table-column>
            <el-table-column
              label="日期"
              prop="date"
              width="80"
              align="center"
              fixed
            >
              <template slot-scope="scope">
                <el-date-picker
                  v-if="editIndex == scope.$index"
                  v-model="scope.row.date"
                  class="dataInputer"
                  placeholder=""
                  type="date"
                  :format="dateFormat"
                  :value-format="dateFormat"
                />
                <span v-if="editIndex != scope.$index">{{
                    scope.row.date
                  }}</span>
              </template>
            </el-table-column>
            <el-table-column
              fixed
              label="时间"
              width="45"
              prop="time"
              align="center"
              :resizable="false"
            >
              <template slot-scope="scope">
                <el-time-picker
                  v-if="editIndex == scope.$index"
                  v-model="scope.row.time"
                  style="text-align: center"
                  format="HH:mm"
                  value-format="HH:mm"
                />
                <span v-if="editIndex != scope.$index">{{
                    scope.row.time
                  }}</span>
              </template>
            </el-table-column>
            <el-table-column
              label="呼吸机编号"
              align="center"
              header-align="center"
              width="80"
            >
              <template slot-scope="scope">
                <el-input
                  v-if="editIndex == scope.$index"
                  v-model="scope.row.number"
                  style="text-align: center"
                />
                <span v-if="editIndex != scope.$index">
                    {{ scope.row.number }}
                  </span>
              </template>
            </el-table-column>
            <el-table-column
              label="生命体征"
              align="center"
              header-align="center"
            >
              <el-table-column
                label="HR(次/分)"
                align="center"
                header-align="center"
                width="80"
              >
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.hr"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.hr }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column
                label="RR(次/分)"
                align="center"
                header-align="center"
                width="80"
              >
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.rr"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.rr }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column
                label="BP(mmHg)"
                align="center"
                header-align="center"
                width="80"
              >
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.bp"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.bp }}
                  </span>
                </template>
              </el-table-column>
              <!--
              <el-table-column
                label="NBP(mmHg)"
                align="center"
                header-align="center"
                width="80"
              >
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.nbps"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.nbps }}
                  </span>
                </template>
              </el-table-column>
              -->
              <el-table-column label="SpO2(%)" align="center">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.spo2"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.spo2 }}
                  </span>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column
              label="参数设置"
              width="auto"
              align="center"
              header-align="center"
            >
              <el-table-column label="MODE" align="center" width="100">
                <template slot-scope="scope">
                  <el-select
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.mode"
                  >
                    <el-option
                      v-for="item in modeList"
                      :key="item.id"
                      :label="item.description"
                      :value="item.description"
                    >
                    </el-option>
                  </el-select>
                  <span v-if="editIndex != scope.$index">{{
                      scope.row.mode
                    }}</span>
                </template>
              </el-table-column>
              <el-table-column label="FiO2(%)" align="center" width="50">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.fio2"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">{{
                      scope.row.fio2
                    }}</span>
                </template>
              </el-table-column>
              <el-table-column label="PEEP(cmH20)" align="center" width="50">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.peep"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">{{
                      scope.row.peep
                    }}</span>
                </template>
              </el-table-column>
              <el-table-column label="F(次/分)" align="center" width="50">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.f"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">{{
                      scope.row.f
                    }}</span>
                </template>
              </el-table-column>
              <el-table-column label="Ti(s)" align="center" width="50">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.ti"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">{{
                      scope.row.ti
                    }}</span>
                </template>
              </el-table-column>
              <el-table-column label="PC(cmH20)" align="center" width="50">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.pc"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">{{
                      scope.row.pc
                    }}</span>
                </template>
              </el-table-column>
              <el-table-column label="Pinsp(cmH20)" align="center" width="50">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.pinsp"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">{{
                      scope.row.pinsp
                    }}</span>
                </template>
              </el-table-column>
              <el-table-column label="Ps(cmH20)" align="center" width="50">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.ps"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">{{
                      scope.row.ps
                    }}</span>
                </template>
              </el-table-column>
              <el-table-column label="VT(ml)" align="center" width="50">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.vt"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">{{
                      scope.row.vt
                    }}</span>
                </template>
              </el-table-column>
              <el-table-column label="I:E" align="center" width="60">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.ie"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">{{
                      scope.row.ie
                    }}</span>
                </template>
              </el-table-column>
              <el-table-column label="Ramp(s)" align="center" width="60">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.ramp"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">{{
                      scope.row.ramp
                    }}</span>
                </template>
              </el-table-column>
              <el-table-column label="IPAP(cmH20)" align="center" width="60">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.ipap"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">{{
                      scope.row.ipap
                    }}</span>
                </template>
              </el-table-column>
              <el-table-column label="EPAP(cmH20)" align="center" width="60">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.epap"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">{{
                      scope.row.epap
                    }}</span>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column
              label="监测值"
              align="center"
              header-align="center"
            >
              <el-table-column
                label="Ppeak(cmH20)"
                align="center"
                header-align="center"
                width="90"
              >
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.ppeak"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.ppeak }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column label="Pplat(cmH20)" align="center" width="90">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.pplat"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.pplat }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column label="Pmean(cmH20)" align="center" width="90">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.pmean"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.pmean }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column label="VTi(ml)" align="center" width="90">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.vti"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.vti }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column label="VTe(ml)" align="center" width="90">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.vte"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.vte }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column label="RR(次/分)" align="center" width="90">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.rrr"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.rrr }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column label="MV(L/min)" align="center" width="90">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.mv"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.mv }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column label="FlowPeak(L/min)" align="center" width="90">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.flowpeak"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.flowpeak }}
                  </span>
                </template>
              </el-table-column>
            </el-table-column>

            <el-table-column
              label="呼吸力学"
              align="center"
              header-align="center"
            >
              <el-table-column label="气道阻力(cmH20/L/s)" align="center" width="90">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.airwayResistance"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.airwayResistance }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column label="顺应性(ml/cmH2O)" align="center" width="90">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.compliance"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.compliance }}
                  </span>
                </template>
              </el-table-column>
            </el-table-column>

            <el-table-column
              label="气道管理与VAP预防"
              align="center"
              header-align="center"
            >
              <el-table-column label="气管插管" align="center" width="90">
                <template slot-scope="scope">
                  <el-select
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.trachealIntubation"
                  >
                    <el-option
                      v-for="item in selectList"
                      :key="item.id"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                  <span v-if="editIndex != scope.$index">{{scope.row.trachealIntubation === "1" ? "✔" : ""}}</span>
                </template>
              </el-table-column>
              <el-table-column label="气管切开" align="center" width="90">
                <template slot-scope="scope">
                  <el-select
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.tracheotomy"
                  >
                    <el-option
                      v-for="item in selectList"
                      :key="item.id"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                  <span v-if="editIndex != scope.$index">{{scope.row.tracheotomy === "1" ? "✔" : ""}}</span>
                </template>
              </el-table-column>
              <el-table-column label="纤支镜检查" align="center" width="90">
                <template slot-scope="scope">
                  <el-select
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.bronchoscopy"
                  >
                    <el-option
                      v-for="item in selectList"
                      :key="item.id"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                  <span v-if="editIndex != scope.$index">{{scope.row.bronchoscopy === "1" ? "✔" : ""}}</span>
                </template>
              </el-table-column>
              <el-table-column label="床头抬高" align="center" width="90">
                <template slot-scope="scope">
                  <el-select
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.bedRise"
                  >
                    <el-option
                      v-for="item in selectList"
                      :key="item.id"
                      :label="item.label"
                      :value="item.value"
                    />
                  </el-select>
                  <span v-if="editIndex != scope.$index">{{scope.row.bedRise === "1" ? "✔" : ""}}</span>
                </template>
              </el-table-column>
              <el-table-column label="套囊压力(cmH20)" align="center" width="90">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.cuffPressure"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.cuffPressure }}
                  </span>
                </template>
              </el-table-column>

            </el-table-column>
            <el-table-column
              label="气囊上滞留物"
              align="center"
              header-align="center"
            >
              <el-table-column label="方式" align="center" width="90">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.ways"
                    type="textarea"
                    :autosize="{ minRows: 7, maxRows: 15 }"
                    @input.native="textAreaChanging($event, scope.$index)"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.ways }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column label="量(ml)" align="center" width="90">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.quantity"
                    style="text-align: center"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.quantity }}
                  </span>
                </template>
              </el-table-column>
              <el-table-column label="颜色" align="center" width="90">
                <template slot-scope="scope">
                  <el-input
                    v-if="editIndex == scope.$index"
                    v-model="scope.row.color"
                    type="textarea"
                    :autosize="{ minRows: 7, maxRows: 15 }"
                    @input.native="textAreaChanging($event, scope.$index)"
                  />
                  <span v-if="editIndex != scope.$index">
                    {{ scope.row.color }}
                  </span>
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column label="咳嗽能力评价" align="center" width="150">
              <template slot-scope="scope">
                <el-input
                  v-if="editIndex == scope.$index"
                  v-model="scope.row.coughAbility"
                  type="textarea"
                  :autosize="{ minRows: 7, maxRows: 15 }"
                  @input.native="textAreaChanging($event, scope.$index)"
                />
                <span v-if="editIndex != scope.$index">
                    {{ scope.row.coughAbility }}
                  </span>
              </template>
            </el-table-column>
            <el-table-column label="雾化吸入方式" align="center" width="150">
              <template slot-scope="scope">
                <el-input
                  v-if="editIndex == scope.$index"
                  v-model="scope.row.aerosolInhalation"
                  type="textarea"
                  :autosize="{ minRows: 7, maxRows: 15 }"
                  @input.native="textAreaChanging($event, scope.$index)"
                />
                <span v-if="editIndex != scope.$index">
                    {{ scope.row.aerosolInhalation }}
                  </span>
              </template>
            </el-table-column>
            <el-table-column label="备注" align="center" width="200">
              <template slot-scope="scope">
                <el-input
                  v-if="editIndex == scope.$index"
                  v-model="scope.row.remark"
                  type="textarea"
                  :autosize="{ minRows: 7, maxRows: 15 }"
                  @input.native="textAreaChanging($event, scope.$index)"
                />
                <div style="text-align: left">
                  <span
                    v-if="editIndex != scope.$index"
                    style="white-space: pre-wrap; word-break: break-all"
                  >{{ scope.row.remark }}</span
                  >
                </div>
              </template>
            </el-table-column>
            <el-table-column label="护士签名" align="center" width="80">
              <template slot-scope="scope">
                <el-select
                  v-if="editIndex == scope.$index"
                  v-model="scope.row.nurseSign"
                  filterable
                  :filter-method="signFilter"
                >
                  <el-option
                    v-for="item in signOptions"
                    :key="item.id"
                    :value="item.user_name"
                  />
                </el-select>
                <span v-if="editIndex != scope.$index">{{
                    scope.row.nurseSign
                  }}</span>
              </template>
            </el-table-column>
            <el-table-column label="接班签名" align="center" width="80">
              <template slot-scope="scope">
                <el-select
                  v-if="editIndex == scope.$index"
                  v-model="scope.row.nurseSignTwo"
                  filterable
                  :filter-method="signFilter"
                >
                  <el-option
                    v-for="item in signOptions"
                    :key="item.id"
                    :value="item.user_name"
                  />
                </el-select>
                <span v-if="editIndex != scope.$index">{{
                    scope.row.nurseSignTwo
                  }}</span>
              </template>
            </el-table-column>
          </el-table>
        </el-row>
        <div class="paging">
          <el-button
            slot="append"
            style="
              width: 100%;
              border-radius: 0;
              border-top: 0;
              border-left: 0;
              border-right: 0;
              position: sticky;
              z-index: 2;
              text-align: center;
            "
            @click="addEmptyRow"
          >点击追加一行</el-button
          >
        </div>
      </el-col>
    </div>
    <!-- 三合一打印内容 ------------------------------------------------------>
    <!--
    <div style="visibility: hidden; display: none"> </div> -->
    <div style="visibility: hidden; display: none">
      <div style="font-size: 5px; height: 90px" :id="printParam.title_id">
        <div
          style="
            width: 100%;
            margin-top: 10px;
            position: relative;
            font-size: 18px;
            height: 30px;
            line-height: 20px;
            margin-bottom: 20px;
          "
        >
          <div style="position: absolute; left: 50%; width: 550px">
            <img
              src="@/icons/img/changzhi.png"
              style="
                width: 45px;
                height: 45px;
                display: inline-block;
                float: left;
                pointer-events: none;
              "
            />
            <div
              style="
                float: left;
                width: 500px;
                font-size: 20px;
                font-weight: bold;
              "
            >
              <span align="center">{{ this.$store.state.City }}医院</span><br />
              <span align="center" style="margin-left: 40px"
              >呼吸治疗记录单</span
              >
            </div>
            <div style="clear: both"></div>
          </div>
        </div>
        <div style="width: 100%; height: 20px">
          <div style="margin-right: 15px; float: left">
            科室：
            {{
              this.data.department_name === "" ? "" : this.data.department_name
            }}
          </div>
          <div style="margin-right: 15px; float: left">
            床号：
            {{ this.data.bed_code === "" ? "" : this.data.bed_code }}
          </div>
          <div style="margin-right: 15px; float: left">
            姓名：
            {{ this.data.name === "" ? "" : this.data.name }}
          </div>
          <div style="margin-right: 15px; float: left">
            性别：
            {{ this.data.sex === "" ? "" : this.data.sex }}
          </div>
          <div style="margin-right: 15px; float: left">
            年龄：
            {{ this.$store.state.user.severFall.ageOrMonthAge}}
          </div>
          <div style="margin-right: 15px; float: left">
            住院号：
            {{ this.data.visit_id === "" ? "" : this.data.visit_id }}
          </div>
          <div style="margin-right: 15px; float: left">
            入科时间：
            {{ this.entertime }}
          </div>
        </div>
        <div style="width: 100%; height: 20px">
          诊断：
          {{ this.data.diagnosis_name }}
        </div>
      </div>

      <el-table
        :id="printParam.table_id"
        :data="printArray"
        :cell-class-name="cellClassName"
        style="width: 100%; display: block"
        :row-class-name="tableRowClassName"
      >
        <el-table-column
          :label="'日\n期'"
          prop="date"
          align="left"
        >
          <template slot-scope="scope">
          <span>{{
              scope.row.date
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          :label="'时\n间'"
          prop="time"
          align="left"
        >
          <template slot-scope="scope">
            <span>{{
                scope.row.time
              }}</span>
          </template>
        </el-table-column>
        <el-table-column
          :label="'呼\n吸\n机\n编\n号'"
          align="center"
          header-align="center"
        >
          <template slot-scope="scope">
            <span>{{ scope.row.number }}</span>
          </template>
        </el-table-column>
        <el-table-column
          label="生命体征"
          align="center"
          header-align="center"
        >
          <el-table-column
            :label="'H\nR\n◠\n次\n/\n分\n◡'"
            align="left"
          >
            <template slot-scope="scope">
              <span>
                    {{ scope.row.hr }}
                  </span>
            </template>
          </el-table-column>
          <el-table-column
            :label="'R\nR\n◠\n次\n/\n分\n◡'"
            align="left"
          >
            <template slot-scope="scope">
              <span>
                    {{ scope.row.rr }}
                  </span>
            </template>
          </el-table-column>
          <el-table-column
            :label="'B\nP\n◠\nm\nm\nH\ng\n◡'"
            align="left"
          >
            <template slot-scope="scope">
              <span>
                    {{ scope.row.bp }}
                  </span>
            </template>
          </el-table-column>
          <!--

          <el-table-column
            :label="'N\nB\nP\n◠\nm\nm\nH\ng\n◡'"
            align="left"
          >
            <template slot-scope="scope">
              <span>
                    {{ scope.row.nbp }}
                  </span>
            </template>
          </el-table-column>
         -->
          <el-table-column :label="'S\np\nO\n2\n◠\n%\n◡'" align="left">
            <template slot-scope="scope">
              <span>
                    {{ scope.row.spo2 }}
                  </span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column
          label="参数设置"
          width="auto"
          align="center"
        >
          <el-table-column :label="'M\nO\nD\nE'" align="left" >
            <template slot-scope="scope">
              <span>{{
                  scope.row.mode
                }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'F\ni\nO\n2\n◠\n%\n◡'" align="left">
            <template slot-scope="scope">
              <span>{{
                  scope.row.fio2
                }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'P\nE\nE\nP\n◠\nc\nm\nH2\n0\n◡'" align="left">
            <template slot-scope="scope">
              <span>{{
                  scope.row.peep
                }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'F\n◠\n次\n/\n分\n◡'" align="left">
            <template slot-scope="scope">
              <span>{{
                  scope.row.f
                }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'T\ni\n◠\ns\n◡'" align="left">
            <template slot-scope="scope">
              <span>{{
                  scope.row.ti
                }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'P\nC\n◠\nc\nm\nH\n2\n0\n◡'" align="left">
            <template slot-scope="scope">
              <span>{{
                  scope.row.pc
                }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'P\ni\nn\ns\np\n◠\nc\nm\nH\n2\n0\n◡'" align="left">
            <template slot-scope="scope">
              <span>{{
                  scope.row.pinsp
                }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'P\ns\n◠\nc\nm\nH\n2\n0\n◡'" align="left">
            <template slot-scope="scope">
              <span>{{
                  scope.row.ps
                }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'V\nT\n◠\nm\nl\n◡'" align="left">
            <template slot-scope="scope">
              <span>{{
                  scope.row.vt
                }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'I\n:\nE'" align="left">
            <template slot-scope="scope">
              <span>{{
                  scope.row.ie
                }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'R\na\nm\np\n◠\ns\n◡'" align="left">
            <template slot-scope="scope">
              <span>{{
                  scope.row.ramp
                }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'I\nP\nA\nP\n◠\nc\nm\nH\n2\n0\n◡'" align="left">
            <template slot-scope="scope">
              <span>{{
                  scope.row.ipap
                }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'E\nP\nA\nP\n◠\nc\nm\nH\n2\n0\n◡'" align="left">
            <template slot-scope="scope">
              <span>{{
                  scope.row.epap
                }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column
          label="监测值"
          align="center"
          header-align="center"
        >
          <el-table-column
            :label="'P\np\ne\na\nk\n◠\nc\nm\nH\n2\n0\n◡'"
            align="center"
            header-align="center"
          >
            <template slot-scope="scope">
              <span>
                    {{ scope.row.ppeak }}
                  </span>
            </template>
          </el-table-column>
          <el-table-column :label="'P\np\nl\na\nt\n◠\nc\nm\nH\n2\n0\n◡'" align="center">
            <template slot-scope="scope">
              <span>
                    {{ scope.row.pplat }}
                  </span>
            </template>
          </el-table-column>
          <el-table-column :label="'P\nm\ne\na\nn\n◠\nc\nm\nH\n2\n0\n◡'" align="center" width="90">
            <template slot-scope="scope">
              <span>
                    {{ scope.row.pmean }}
                  </span>
            </template>
          </el-table-column>
          <el-table-column :label="'V\nT\ni\n◠\nm\nl\n◡'" align="center" width="90">
            <template slot-scope="scope">
              <span>
                    {{ scope.row.vti }}
                  </span>
            </template>
          </el-table-column>
          <el-table-column :label="'V\nT\ne\n◠\nm\nl\n◡'" align="center" width="90">
            <template slot-scope="scope">
              <span>
                    {{ scope.row.vte }}
              </span>
            </template>
          </el-table-column>
          <el-table-column :label="'R\nR\n◠\n次\n/\n分\n◡'" align="center" width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.rrr }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'M\nV\n◠\nL\n/\nm\ni\nn\n◡'" align="center" width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.mv }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'F\nl\no\nw\nP\ne\na\nk\n◠\nL\n/\nm\ni\nn\n◡'" align="center" width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.flowpeak }}</span>
            </template>
          </el-table-column>
        </el-table-column>

        <el-table-column
          label="呼吸力学"
          align="center"
          header-align="center"
        >
          <el-table-column :label="'气\n道\n阻\n力\n◠\nc\nm\nH\n2\n0\n/\nL\n/\ns\n◡'" align="center" width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.airwayResistance }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'顺\n应\n性\n◠\nm\nl\n/\nc\nm\nH\n2\nO\n◡'" align="center" width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.compliance }}</span>
            </template>
          </el-table-column>
        </el-table-column>

        <el-table-column
          label="气道管理与VAP预防"
          align="center"
          header-align="center"
        >
          <el-table-column :label="'气\n管\n插\n管'" align="center" width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.trachealIntubation=== "1" ? "✔" : "" }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'气\n管\n切\n开'" align="center" width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.tracheotomy === "1" ? "✔" : ""}}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'纤\n支\n镜\n检\n查'" align="center" width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.bronchoscopy=== "1" ? "✔" : "" }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'床\n头\n抬\n高'" align="center" width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.bedRise=== "1" ? "✔" : "" }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'套\n囊\n压\n力\n◠\nc\nm\nH\n2\n0\n◡'" align="center" width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.cuffPressure }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column
          label="气囊上滞留物"
          align="center"
          header-align="center"
        >
          <el-table-column :label="'方\n式'" align="center" width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.ways }} </span>
            </template>
          </el-table-column>
          <el-table-column :label="'量\n◠\nm\nl\n◡'" align="center" width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.quantity }}</span>
            </template>
          </el-table-column>
          <el-table-column :label="'颜\n色'" align="center" width="90">
            <template slot-scope="scope">
              <span>{{ scope.row.color }}</span>
            </template>
          </el-table-column>
        </el-table-column>
        <el-table-column :label="'咳\n嗽\n能\n力\n评\n价'" align="center" width="80">
          <template slot-scope="scope">
            <span>{{ scope.row.coughAbility }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="'雾\n化\n吸\n入\n方\n式'" align="center" width="80">
          <template slot-scope="scope">
            <span >{{ scope.row.aerosolInhalation }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="'备\n注'" align="center" width="200">
          <template slot-scope="scope">
            <div style="text-align: left">
              <span style="white-space: pre-wrap; word-break: break-all">{{ scope.row.remark }}</span>
            </div>
          </template>
        </el-table-column>
        <el-table-column :label="'护\n士\n签\n名'" align="left">
          <template slot-scope="scope">
            <div>
              <span
                style="
                  display: inline-block;
                  white-space: nowrap;
                  word-break: keep-all;
                "
              >
                {{ scope.row.nurseSign }}</span
              >
            </div>
            <div>
              <span
                style="
                  display: inline-block;
                  white-space: nowrap;
                  word-break: keep-all;
                "
              >{{ scope.row.nurseSignTwo }}</span
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { jyxdPrint } from "../../utils/jyxd-printer";
import * as math from "mathjs";
import nursingPrompt from "@/views/nursingDocument/combinedSheetPrompt.vue";
import orderList from "@/views/nursingDocument/orderList.vue";
import { dateUtils } from "@/utils/dateUtils";
import nursingTemplate from "@/views/nursingDocument/nursingTemplate.vue";
import { Message } from "element-ui";
import { json } from "mathjs";
import request from "@/utils/request";

import {
  usergetList,
  findPage,
  getCombinedCodeList,
  breatheSystemFormgetListPage,
  breatheSystemForminsert,
  breatheSystemFormdeleteById,
  getCombinedSheetUseSurplus,
  getCombinedSheetSummaryOrSummarize,
  patientCriticalDescriptiongetNewCriticalDescription,
  queryDataMaibo,
  openPulseRecord,
  getCommonSettingByPatientId,
  NursingUpdateOnOrOff,
  updateDefaultPage,
  getListlei,
  nurseRecordFormOutPutqueryList,
  nurseRecordFormPipeLengthQueryList,
  getUserListByUserType,
  byParentIdCount,
  getCodeListByName, QueryNewestList, getUserListByUserTypegetNurseList,
} from "@/api/table";

export default {
  components: {
  },
  props: {},
  data() {
    return {
      settingName: "respiratorySheetSetting", //保存设置之名字
      queryBeginDate: "", //查询开始时间
      queryEndDate: "", //查询结束时间
      loading: false, //查询中
      entertime: "", //入科时间
      pageStartNumber: "", //起始页码
      modeList: [],//呼吸机模式list
      loginName: "", //当前登录人
      arrTypelist: [],
      orderIndex: "", //行数据
      selectTime: true, //控制选择的时间不能超过当前时间
      age: "",
      tableHeight: 1000,
      dialogVisible: false,
      start_time: "",
      end_time: "",
      rowIndex: "",
      //打印表格列定义,options_name是下拉项传回的变量名，不用代号打印的列置空
      //dividable:该列是否允许跨页拆分，yes/no
      //hidden:该列是否隐藏不打印，yes/no
      printParam: {
        table_id: "mytable", //表实体div id，<el-table>表内容不能全空，至少有一行，即使是空行
        title_id: "myheader", //表前抬头栏div 的id，如果没有或不需打印，去除此变量或置空或置"无"
        tail_id: "mytail", //表后签字栏div 的id，如果没有或不需打印，去除此变量或置空或置"无"
        page_rows: 9, //首页行数，0，表示不分页
        second_rows: 8, //首页之外各页的行数，只在首页打印抬头的话首页行数和其它页行数会不同
        paper_height: "1450", //纸张长度，设为大于500的值表示自动按纸张长度分页，设其它值都按每页行数分页。
        //例如A4纸长度大概在1040-1400之间。
        //纸张长度分页优于按行数分页，设置纸张长度后，每页行数的设置被忽略不用。
        //严重折行的表格按纸张长度分页可能会造成分页错误，预览到错误后可以调整纸张长度纠正。
        paper_width: "2200",
        table_head: "", //非el-table表的表头id，表前部不变部分，用<tbody id=>  </tbody>括起来
        table_body: "text-align: left", //非el-table表的表体id，填充数据部分，用<tbody id=>  </tbody>括起来
        table_foot: "", //非el-table表的表脚id，表里不变部分，用<tbody id=>  </tbody>括起来
        button: "", //是否打印按钮，置"button"或"打印"表示输出按钮，去除此变量或置空将隐藏所有按钮
        title: "", //是否每页都要页面抬头，置"first"或"首页"表示只有首页打印抬头，去除此变量或置空所有页面都有抬头
        tail: "", //是否每页都要页面签字栏，置"first"或"首页"表示只有首页打印签字栏，去除此变量或置空所有页面都有签字栏
        blank: 0, //打印空表页数，空表保留所有上述格式，内容为空。0表示打印实际数据表。
        hidden_col: "", //隐藏列号范围，如 "0,2-4,9"，列号从0起计，去除此变量或置空表示打印所有列。复杂表头暂不支持列隐藏。
        preview: "预览", //是否仅仅预览？置"预览"表示仅展示在屏幕上，置空表示表示直接调用print()。
        thead_style: "font-size:14px;white-space: pre-line;",
        tbody_style: "font-size:14px",
        tail_style: "",
        title_font: "宋体",
        title_font_size: 14,
        tail_font_size: 14,
        tail_font: "宋体",
        thead_font: "宋体",
        thead_font_size: 14,
        tbody_font_size: 14,
        tbody_font: "宋体",
        title_style: "",
        tfoot_style: "",
        col_width: [
          { col: 0, width: 90 }, //日期
          { col: 1, width: 60 }, //时间
          { col: 2, width: 50 }, //number
          { col: 3, width: 50 }, //hr
          { col: 4, width: 50 }, //rr
          { col: 5, width: 70 }, //bp
          { col: 6, width: 50 }, //spo2
          { col: 7, width: 100 }, //mode
          { col: 8, width: 50 }, //fio2
          { col: 9, width: 50 }, //peep
          { col: 10, width: 50 }, //f
          { col: 11, width: 50 }, //ti
          { col: 12, width: 50 }, //pc
          { col: 13, width: 50 }, //pinsp
          { col: 14, width: 50 }, //ps
          { col: 15, width: 50 }, //vt
          { col: 16, width: 50 }, //ie
          { col: 17, width: 50 }, //ramp
          { col: 18, width: 50 }, //ipap
          { col: 19, width: 50 }, //ppeak
          { col: 20, width: 50 }, //pplat
          { col: 21, width: 50 }, //pmean
          { col: 22, width: 50 }, //vti
          { col: 23, width: 50 }, //vte
          { col: 24, width: 50 }, //rrr
          { col: 25, width: 50 }, //mv
          { col: 26, width: 50 }, //flow
          { col: 27, width: 50 }, //气道阻力
          { col: 28, width: 50 }, //顺应性
          { col: 29, width: 50 }, //顺应性
          { col: 30, width: 35 }, //气管插管
          { col: 31, width: 35 }, //气管切开
          { col: 32, width: 35 }, //纤支镜检查
          { col: 33, width: 35 }, //床头抬高
          { col: 34, width: 50 }, //套囊压力
          { col: 35, width: 100 }, //方式
          { col: 36, width: 50 }, //量
          { col: 37, width: 100 }, //颜色
          { col: 38, width: 150 }, //评价
          { col: 39, width: 100 }, //方式
          { col: 40, width: 180 }, //备注
          { col: 41, width: 75 }, //护士签名
        ],
        divide_cols: [7,35,37, 38, 39, 40], //允许拆分的列号
        debug: "yes", //不打印debug信息
      },
      user_name: "",
      associatedTable: "",
      data: {}, //患者信息
      //表格数据
      //-----------打印用
      printArray: [],
      //-----------------编辑用
      dataArray: [],
      queryLoading: false,
      editIndex: -1, //编辑行号，从0开始
      editIndexs: -1,
      lastRowData: {}, //保存回滚值
      editRowHeight: 28, //行高
      revisableDays: 2, //指定多少天前的数据被保护，不允许修改删除
      aheadMinutes: 10, //允许提前多少分钟录入数据，即可以选择未来的时刻
      ignoredKeys: ["index", "date", "time", "signature", "secondSign"], //判是否空行时忽略不计的变量名
      //值变化的列
      changedFields: [], //哪些列的值被修改了？
      dateFormat: "yyyy-MM-dd", //显示日期格式
      arrUserName: [],
      signOptions: [],
      editIndex1: -1, //自定义用
      actionColumnFlag: true,
      start: 1, // 默认显示第几页
      totalCount: 0, // 总条数，根据接口获取数据长度(注意 : 这里不能为空)
      pgeSizes: [10, 20, 30, 40], // 个数选择器（可修改）
      PageSize: 10, // 默认每页显示的条数（可修改）
      pageFlag: false,
      addFlag: true,
      pulseFlag: true, //脉搏开启状态
      selectLoading: false,
      selectList: [
        {
          id: "0",
          value: "1",
          label: "是",
        },
        {
          id: "1",
          value: "0",
          label: "否",
        },
      ],
    };
  },
  created() {
    this.initData();
  },
  computed: {
    getData() {
      return this.$store.state.user.severFall;
    },
  },
  methods: {
    signFilter(val) {
      this.value = val;
      if (val) { //val存在
        this.signOptions = this.arrUserName.filter((item) => {
          if (item.user_name.indexOf(val) >= 0 || item.login_name.indexOf(val) >=0 ) {
            return true
          }
        })
      } else { //val为空时，还原数组
        Object.assign(this.signOptions,this.arrUserName);
      }
    },
    //初始化数据
    initData() {
      const flag = this.selectPatientFlag();
      if (!flag) {
        Message({
          message: "请选择患者",
          type: "warning",
          duration: 1500,
        });
        return;
      }

      //获取签名列表
      getUserListByUserTypegetNurseList({
        deptCode: this.$store.state.user.loginInfo.deptCode
      }).then((res) => {
        this.arrUserName = res.data;
        Object.assign(this.signOptions, res.data);
      });
      getCodeListByName({ status: 1, commonName: "MODE" }).then((res) => {
        this.modeList = res.data;
      });

      //赋值患者入科时间、赋值查询时间、赋值起始页码、赋值备注内容列表、赋值当前登录人名称、赋值初始化参数、查询患者参数、危急值
      //脉率状态
      this.entertime = this.data.enter_time;
      this.setInOutOrQueryDate();
      //根据当前时间判断赋值
      this.findPageByPatientId();
      this.loginName = this.$store.state.user.name;
      this.readSetting();
      this.editIndex = -1;
      this.queryDataArray();
      setTimeout(() => {
        if (typeof self.$refs.mainTable != "undefined") {
          this.tableHeight =
            window.innerHeight - this.$refs.mainTable.$el.offsetTop - 200;
        }
      }, 3000);
      let self = this;
      window.onresize = function () {
        if (typeof self.$refs.mainTable != "undefined") {
          self.tableHeight =
            window.innerHeight - self.$refs.mainTable.$el.offsetTop - 200;
        }
      };
    },
    //==================初始化参数的方法===============================
    //保存打印参数
    saveSetting() {
      localStorage.setItem(this.settingName, JSON.stringify(this.printParam));
      this.$message({ message: "已保存", type: "success", duration: 800 });
    },
    //初始化打印参数
    readSetting() {
      var str = localStorage.getItem(this.settingName);
      if (str == null) {
        this.printParam.page_rows = "18";
        this.printParam.second_rows = "20";
        this.printParam.paper_height = "1450";
        this.printParam.paper_width = "2200";
        this.printParam.countingTime = "07:00:00";
        this.printParam.countingHours = "12";
        this.printParam.summaryHours = "24";
      } else {
        var json = JSON.parse(str);
        if (json != null) {
          this.printParam.page_rows = json.page_rows;
          this.printParam.second_rows = json.second_rows;
          this.printParam.paper_height = json.paper_height;
          this.printParam.paper_width = json.paper_width;
          this.printParam.countingTime = json.countingTime;
          this.printParam.countingHours = json.countingHours;
          this.printParam.summaryHours = json.summaryHours;
        }
      }
    },
    //根据时间判断显示的时间
    setInOutOrQueryDate() {
      var toady = dateUtils(2, null);
      var compareDate = dateUtils(1, null) + " 08:30:00";
      var nextDate = new Date();
      nextDate.setTime(nextDate.getTime() + 24 * 60 * 60 * 1000);
      var topDate = new Date();
      topDate.setTime(topDate.getTime() - 24 * 60 * 60 * 1000);
      if (this.compare(toady, compareDate)) {
        this.queryBeginDate = dateUtils(1, null);
        this.queryEndDate = dateUtils(1, nextDate);
      } else {
        this.queryBeginDate = dateUtils(1, topDate);
        this.queryEndDate = dateUtils(1, null);
      }
    },
    //判断是否选择患者
    selectPatientFlag() {
      this.data = this.$store.state.user.severFall;
      if (this.data.patient_id == undefined) {
        return false;
      }
      return true;
    },
    //查询患者信息
    findPatientById() {
      queryDataMaibo({ patientId: this.data.patient_id }).then((res) => {
        this.heimeisu = res.data.diagnosis_name;
        if (res.data[0].enter_time !== "") {
          this.entertime = res.data[0].enter_time;
        }
        if (res.data[0].age !== "") {
          this.age = res.data[0].age;
        }
      });
    },
    //页码设置
    findPageByPatientId() {
      findPage({
        patientId: this.data.patient_id,
      }).then((res) => {
        if (res.data != null && res.data.length > 0) {
          this.printParam.pageStartNumber = res.data[0].pageNum;
        } else {
          this.printParam.pageStartNumber = "";
        }
      });
    },
    //=====================初始化end================================
    //=====================功能项==============================
    //添加空数据行，无实质内容，除了时间和签名
    addEmptyRow() {
      const flag = this.selectPatientFlag();
      if (!flag) {
        Message({
          message: "请选择患者",
          type: "warning",
          duration: 1500,
        });
        return;
      }
      if (this.editIndex >= 0) {
        Message({
          message: "前次编辑未结束!",
          type: "warning",
          duration: 1500,
        });
        return;
      }
      if (typeof this.dataArray != "undefined") {
        var item = {
          index: "",
          date: "",
          time: "",
          number:"",
          hr:"",
          rr:"",
          bp:"",
          nbps:"",
          spo2:"",
          mode:"",
          fio2:"",
          peep:"",
          f:"",
          ti:"",
          pc:"",
          pinsp:"",
          ps:"",
          vt:"",
          ie:"",
          ramp:"",
          ipap:"",
          epap:"",
          ppeak:"",
          pplat:"",
          pmean:"",
          vti:"",
          vte:"",
          rrr:"",
          mv:"",
          flowpeak:"",
          airwayResistance:"",
          compliance:"",
          trachealIntubation:"",
          tracheotomy:"",
          bronchoscopy:"",
          bedRise:"",
          cuffPressure:"",
          ways:"",
          quantity:"",
          color:"",
          coughAbility:"",
          aerosolInhalation:"",
          remark:"",
          nurseSign:"",
          nurseSignTwo:"",
          status:1,
          createTime:"",
        };
        var index = "";
        if (this.dataArray.length > 0) {
          index = this.dataArray.length;
        } else {
          index = 0;
        }
        item.index = index;
        var date = new Date();
        item.date = dateUtils(1, date);
        item.time = dateUtils(8, date);
        item.nurseSign = this.$store.state.user.name;
        //获取最新的生命体征
        QueryNewestList({
          patientId: this.data.patient_id,
          status: "1",
        }).then((res) => {
          if (res.data != null) {
            this.lifeData = res.data;
            item.hr=res.data.hr;
            item.rr=res.data.resp;
            if(res.data.arts!=null && res.data.arts!="" && res.data.artd!=null && res.data.artd!=""){
              item.bp=res.data.arts+"/"+res.data.artd;
            }
            if(res.data.nibps!=null && res.data.nibps!="" && res.data.nibpd!=null && res.data.nibpd!=""){
              item.nbps=res.data.nibps+"/"+res.data.nibpd;
            }
            item.spo2=res.data.spo2;
          }else{
            item.hr="";
            item.rr="";
            item.bp="";
            item.nbps="";
            item.spo2="";
          }
          if (this.dataArray.length > 0) {
            item.number=this.dataArray[index-1].number;
            //item.hr=this.dataArray[index-1].hr;
            //item.rr=this.dataArray[index-1].rr;
            //item.bp=this.dataArray[index-1].bp;
            //item.nbp=this.dataArray[index-1].nbp;
            //item.spo2=this.dataArray[index-1].spo2;
            item.mode=this.dataArray[index-1].mode;
            item.fio2=this.dataArray[index-1].fio2;
            item.peep=this.dataArray[index-1].peep;
            item.f=this.dataArray[index-1].f;
            item.ti=this.dataArray[index-1].ti;
            item.pc=this.dataArray[index-1].pc;
            item.pinsp=this.dataArray[index-1].pinsp;
            item.ps=this.dataArray[index-1].ps;
            item.vt=this.dataArray[index-1].vt;
            item.ie=this.dataArray[index-1].ie;
            item.ramp=this.dataArray[index-1].ramp;
            item.epap=this.dataArray[index-1].epap;
            item.ipap=this.dataArray[index-1].ipap;
            item.ppeak=this.dataArray[index-1].ppeak;
            item.pplat=this.dataArray[index-1].pplat;
            item.pmean=this.dataArray[index-1].pmean;
            item.vti=this.dataArray[index-1].vti;
            item.vte=this.dataArray[index-1].vte;
            item.rrr=this.dataArray[index-1].rrr;
            item.mv=this.dataArray[index-1].mv;
            item.flowpeak=this.dataArray[index-1].flowpeak;
            item.airwayResistance=this.dataArray[index-1].airwayResistance;
            item.compliance=this.dataArray[index-1].compliance;
            item.trachealIntubation=this.dataArray[index-1].trachealIntubation;
            item.tracheotomy=this.dataArray[index-1].tracheotomy;
            item.bronchoscopy=this.dataArray[index-1].bronchoscopy;
            item.bedRise=this.dataArray[index-1].bedRise;
            item.cuffPressure=this.dataArray[index-1].cuffPressure;
            item.ways=this.dataArray[index-1].ways;
            item.quantity=this.dataArray[index-1].quantity;
            item.color=this.dataArray[index-1].color;
            item.coughAbility=this.dataArray[index-1].coughAbility;
            item.aerosolInhalation=this.dataArray[index-1].aerosolInhalation;
            item.nurseSign= this.dataArray[index-1].nurseSign == "" ? this.$store.state.user.name: this.dataArray[index-1].nurseSign;
            //item.nurseSignTwo=this.dataArray[index-1].nurseSignTwo;
          }
          this.dataArray.push(item);
          this.editIndex = item.index;
          //滚到最后
          this.$nextTick(() => {
            let container = this.$el.querySelector(".el-table__body-wrapper");
            container.scrollTop = container.scrollHeight;
          });
          this.$forceUpdate();
        });
      }
    },
    //双击将当前的序号放入数据中
    cellClassName({ row, column, columnIndex }) {
      column.index = columnIndex;
    },
    tableRowClassName({ row, rowIndex }) {
      //把每一行的索引放进row
      if (typeof row == "undefined") return "";
      row.index = rowIndex;
      if (rowIndex == this.editIndex) return "edit-line";
      else return "";
    },
    //===========================双击编辑==================================
    rowDbClick(row, column, ev) {
      this.qingwayi = row;
      this.qingwaer = row.index;
      //判断是否允许双击
      if (row.flag) return;
      if (typeof row == "undefined") return;
      if (this.editIndex >= 0) {
        Message({
          message: "前次编辑未结束!",
          type: "warning",
          duration: 1500,
        });
        return;
      }
      //保存旧数据
      this.changedFields = [];
      this.lastRowData = JSON.parse(JSON.stringify(this.dataArray[row.index]));
      this.enterEditStyle(row.index, ev.target);
      this.editIndex = row.index;
    },
    //===========================点击行编辑==================================
    editButtonClick(index, ev, scope) {
      if (this.editIndex >= 0) {
        Message({
          message: "前次编辑未结束!",
          type: "warning",
          duration: 1500,
        });
        return;
      }
      if (index == this.editIndex) return;
      //保存旧数据
      this.changedFields = [];
      this.lastRowData = JSON.parse(JSON.stringify(this.dataArray[index]));
      var height = this.editRowHeight;
      var obj = ev.target.parentNode;
      this.enterEditStyle(index, ev.target.parentNode);
      this.editIndex = index;
    },
    //进入编辑样式
    enterEditStyle(index, cell) {
      if (this.editRowHeight == "integer" && parseInt(this.editRowHeight) > 10)
        var height = this.editRowHeight;
      else var height = 40;

      var obj = cell;
      while (
        typeof obj == "object" &&
        typeof obj.tagName.toLowerCase() == "string"
        ) {
        if (obj.tagName.toLowerCase() == "tr") {
          height = obj.clientHeight;
          break;
        } else if (obj.tagName.toLowerCase() == "tbody") break;
        else obj = obj.parentNode;
      }
      this.editRowHeight = height;
      document.body.style.setProperty("--editRowHeight", height + "px");
    },
    //===========================删除==================================
    deleteButtonClick(index, row) {
      if (this.editIndex >= 0) {
        Message({
          message: "前次编辑未结束!",
          type: "warning",
          duration: 1500,
        });
        return;
      }
      if (!confirm("确认删除吗?")) return;
      breatheSystemFormdeleteById({
        id: this.dataArray[index].id,
      }).then((res) => {
        this.$message({
          message: "删除成功",
          type: "success",
        });
        this.queryDataArray();
      });
      this.changedFields = [];
      this.editIndex = -1;
    },
    //将字符串转成数字
    getIntValue(str) {
      if (typeof str != "string" || str.length < 1) {
        return 0.0;
      } else {
        str = str.trim();
        return parseFloat(str);
      }
    },
    //====================取消===================================
    reverseButtonClick(index) {
      if (index < 0) return;
      if (
        JSON.stringify(this.dataArray[index]) !=
        JSON.stringify(this.lastRowData)
      ) {
        //if (!this.isEmptyRow(index)) {
        if (!confirm("确认放弃修改, 恢复原值吗?")) return;
        //}
      }
      this.$set(this.dataArray, index, this.lastRowData);
      document.body.style.setProperty(
        "--editRowHeight",
        this.editRowHeight + "px"
      );
      this.editIndex = -1;
    },
    //====================保存===================================
    saveButtonClick(indexOne, index) {
      if (index < 0) return;
      var dtStr = indexOne.row.date + " " + indexOne.row.time + ":00";
      this.editIndex = -1;
      this.insertRow(index);
    },
    insertRow(index) {
      if (
        index < 0 ||
        typeof this.dataArray != "object" ||
        this.dataArray.length <= index
      )
        return;
      var dtStr =
        this.dataArray[index].date + " " + this.dataArray[index].time + ":00";
      //判断录入时间是否大于当前时间
      if (this.selectTime) {
        if (this.compare(dtStr, dateUtils(2, new Date()))) {
          Message({
            message: "录入时间大于当前时间不能录入！！",
            type: "warning",
            duration: 1500,
          });
          return;
        }
      }
      this.data = this.$store.state.user.severFall;
      console.log(this.dataArray[index]);
      console.log(this.dataArray[index].nbps);
      if (this.dataArray[index].id == "") {
        breatheSystemForminsert({
          visitId: this.data.visit_id,
          visitCode: this.data.visit_code,
          patientId: this.data.patient_id,
          dataTime: dtStr,
          status: "1",
          date: this.dataArray[index].date,
          time: this.dataArray[index].time,
          number:this.dataArray[index].number,
          hr:this.dataArray[index].hr,
          rr:this.dataArray[index].rr,
          bp:this.dataArray[index].bp,
          nbps:this.dataArray[index].nbps,
          spo2:this.dataArray[index].spo2,
          mode:this.dataArray[index].mode,
          fio2:this.dataArray[index].fio2,
          peep:this.dataArray[index].peep,
          f:this.dataArray[index].f,
          ti:this.dataArray[index].ti,
          pc:this.dataArray[index].pc,
          pinsp:this.dataArray[index].pinsp,
          ps:this.dataArray[index].ps,
          vt:this.dataArray[index].vt,
          ie:this.dataArray[index].ie,
          ramp:this.dataArray[index].ramp,
          ipap:this.dataArray[index].ipap,
          epap:this.dataArray[index].epap,
          ppeak:this.dataArray[index].ppeak,
          pplat:this.dataArray[index].pplat,
          pmean:this.dataArray[index].pmean,
          vti:this.dataArray[index].vti,
          vte:this.dataArray[index].vte,
          rrr:this.dataArray[index].rrr,
          mv:this.dataArray[index].mv,
          flowpeak:this.dataArray[index].flowpeak,
          airwayResistance:this.dataArray[index].airwayResistance,
          compliance:this.dataArray[index].compliance,
          trachealIntubation:this.dataArray[index].trachealIntubation,
          tracheotomy:this.dataArray[index].tracheotomy,
          bronchoscopy:this.dataArray[index].bronchoscopy,
          bedRise:this.dataArray[index].bedRise,
          cuffPressure:this.dataArray[index].cuffPressure,
          ways:this.dataArray[index].ways,
          quantity:this.dataArray[index].quantity,
          color:this.dataArray[index].color,
          coughAbility:this.dataArray[index].coughAbility,
          aerosolInhalation:this.dataArray[index].aerosolInhalation,
          remark:this.dataArray[index].remark,
          nurseSign:this.dataArray[index].nurseSign,
          nurseSignTwo:this.dataArray[index].nurseSignTwo,
        }).then((res) => {
          if (res.code == 200) {
            this.editIndex = -1;
            this.queryDataArray();
          } else {
            Message({
              message: res.msg,
              type: "warning",
              duration: 1500,
            });
          }
        });
      } else {
        breatheSystemForminsert({
          visitId: this.data.visit_id,
          visitCode: this.data.visit_code,
          patientId: this.data.patient_id,
          dataTime: dtStr,
          status: "1",
          date: this.dataArray[index].date,
          time: this.dataArray[index].time,
          number:this.dataArray[index].number,
          hr:this.dataArray[index].hr,
          rr:this.dataArray[index].rr,
          bp:this.dataArray[index].bp,
          nbps:this.dataArray[index].nbps,
          spo2:this.dataArray[index].spo2,
          mode:this.dataArray[index].mode,
          fio2:this.dataArray[index].fio2,
          peep:this.dataArray[index].peep,
          f:this.dataArray[index].f,
          ti:this.dataArray[index].ti,
          pc:this.dataArray[index].pc,
          pinsp:this.dataArray[index].pinsp,
          ps:this.dataArray[index].ps,
          vt:this.dataArray[index].vt,
          ie:this.dataArray[index].ie,
          ramp:this.dataArray[index].ramp,
          ipap:this.dataArray[index].ipap,
          epap:this.dataArray[index].epap,
          ppeak:this.dataArray[index].ppeak,
          pplat:this.dataArray[index].pplat,
          pmean:this.dataArray[index].pmean,
          vti:this.dataArray[index].vti,
          vte:this.dataArray[index].vte,
          rrr:this.dataArray[index].rrr,
          mv:this.dataArray[index].mv,
          flowpeak:this.dataArray[index].flowpeak,
          airwayResistance:this.dataArray[index].airwayResistance,
          compliance:this.dataArray[index].compliance,
          trachealIntubation:this.dataArray[index].trachealIntubation,
          tracheotomy:this.dataArray[index].tracheotomy,
          bronchoscopy:this.dataArray[index].bronchoscopy,
          bedRise:this.dataArray[index].bedRise,
          cuffPressure:this.dataArray[index].cuffPressure,
          ways:this.dataArray[index].ways,
          quantity:this.dataArray[index].quantity,
          color:this.dataArray[index].color,
          coughAbility:this.dataArray[index].coughAbility,
          aerosolInhalation:this.dataArray[index].aerosolInhalation,
          remark:this.dataArray[index].remark,
          nurseSign:this.dataArray[index].nurseSign,
          nurseSignTwo:this.dataArray[index].nurseSignTwo,
          id: this.dataArray[index].id,
        }).then((res) => {
          if (res.code == 200) {
            this.editIndex = -1;
            this.queryDataArray();
          } else {
            Message({
              message: res.msg,
              type: "warning",
              duration: 1500,
            });
          }
        });
      }
    },
    //====================查询===================================
    queryDataArray() {
      if (
        this.queryBeginDate == "" ||
        this.queryBeginDate == null ||
        this.queryEndDate == "" ||
        this.queryBeginDate == null
      ) {
        Message({
          message: "开始和结束时间不能为空!",
          type: "warning",
          duration: 1500,
        });
        return;
      }
      if (!this.compare(this.queryEndDate, this.queryBeginDate)) {
        Message({
          message: "开始时间必须小于结束时间!",
          type: "warning",
          duration: 1500,
        });
        return;
      }
      var startDateTime = this.queryBeginDate + " 07:00:00";
      var endDateTime = this.queryEndDate + " 07:00:00";
      var startDate = new Date(startDateTime).getTime();
      var endDate = new Date(endDateTime).getTime();
      var hours = Math.ceil((endDate - startDate) / (1000 * 3600));
      breatheSystemFormgetListPage({
        patientId: this.data.patient_id,
        startTime: startDateTime,
        hour: hours,
      })
        .then((res) => {
          if (res.data) {
            this.dataArray = res.data;
            this.queryLoading = false;
            this.editIndex = -1;
          } else {
            this.dataAarray = [];
            this.queryLoading = false;
            this.editIndex = -1;
          }
        })
        .catch((err) => {
          this.queryLoading = false;
        });
    },

    //====================打印===================================
    //打印
    printAllButtonClick() {
      alert("请选择A3打印机横向打印！！");
      this.queryAndPrintAll();
    },
    //根据病人id及入科时间，获得自病人入科以来的全部数据，并打印
    //打印
    queryAndPrintAll() {
      this.loading = true;
      this.data = this.$store.state.user.severFall;
      var dtStr = this.data.enter_time;
      var hours = this.getHours(this.data.enter_time);
      let thus = this;
      breatheSystemFormgetListPage({
        patientId: this.data.patient_id,
        startTime: dtStr,
        hour: hours,
      })
        .then((res) => {
          if (res.data) {
            thus.printArray = res.data;
            thus.$nextTick(function () {
              thus.printOut();
            });
            thus.loading = false;
          } else {
            this.loading = false;
            this.printAarray = [];
            Message({
              message: "未查询到打印数据!",
              type: "warning",
              duration: 1500,
            });
          }
        })
        .catch((err) => {
          this.loading = false;
        });
    },
    //使用当前时间减去入科时间计算时间间隔
    getHours() {
      var dtStr = this.data.enter_time;
      var enter_time = new Date(dtStr).getTime();
      var today = new Date().getTime();
      var hours = Math.ceil((today - enter_time) / (1000 * 3600)) + 24;
      return hours;
    },
    printOut() {
      jyxdPrint(this.printParam);
      this.printArray = [];
    },
    //日期比较的方法 2020-11-15 17:59:20’;
    compare(date1, date2) {
      let dates1 = new Date(date1);
      let dates2 = new Date(date2);
      if (dates1 > dates2) {
        return true;
      } else {
        return false;
      }
    },
    cellStyle(row, column, rowIndex, columnIndex) {
      //根据报警级别显示颜色
      if (row.row.flag === "小结") {
        return "background:blue;color: white";
      } else if (row.row.flag === "总结") {
        return "background:red;color: white";
      }
    },
    //同步生命体征

    //==================行数据处理===========================
    //多行文本输入自动调整行高
    textAreaChanging(ev, index) {
      document.body.style.setProperty(
        "--editRowHeight",
        ev.target.scrollHeight + "px"
      );
    },
  },
};
</script>
<style scoped>
.input-line {
  margin-bottom: 10px;
  float: right;
  font-size: 12px;
}
.el-table td.is-center {
  text-align: left;
}
.tianwangjizai {
  text-align: left;
  display: inline-block;
}
.el-table th.is-center,
.el-table td.is-center {
  text-align: left;
}
body .el-table th.gutter {
  display: table-cell !important;
}
</style>
<style>
.el-table td.is-center {
  text-align: left;
}
.customer-table {
  border-top: 1px solid #000;
  border-left: 1px solid #000;
  border-bottom: 1px solid #000;
}
.customer-table td,
.customer-table th.is-leaf,
.customer-table thead.is-group th {
  border-right: 1px solid #000;
  border-bottom: 1px solid #000;
}
.customer-table .el-table__empty-block {
  border-right: 1px solid #000;
}
</style>
<style lang="scss" scoped>
.el-table td.is-center {
  text-align: left;
}
.tianwangjizai {
  text-align: left;
  display: inline-block;
}
::v-deep .el-table td {
  padding-top: 0px;
  padding-bottom: 0px;
  vertical-align: middle !important;
}
::v-deep .el-table__append-wrapper {
  width: 1893px;
  overflow: visible;
}
::v-deep .el-input__inner {
  padding: 0px;
  margin: 0px;
  border: none;
  outline: none;
  border-radius: 0px;
  color: red;
  background-color: rgb(250 249 222);
}
::v-deep .el-textarea__inner {
  padding: 0px;
  margin: 0px;
  border: none;
  outline: none;
  border-radius: 0px;
  color: red;
}
::v-deep .el-table .cell {
  padding: 0 !important;
  vertical-align: middle;
}
::v-deep .edit-line .cell {
  padding: 0 !important;
  vertical-align: middle;
  position: relative;
  background-color: rgb(250 249 222);
}
::v-deep .edit-line .el-input__inner {
  padding: 0 !important;
  vertical-align: middle;

  color: red;
  background-color: rgb(250 249 222);
}
::v-deep .edit-line .el-textarea__inner {
  padding: 0 !important;
  vertical-align: middle;
  overflow: hidden;
  color: red;
  background-color: rgb(250 249 222);
}
::v-deep .edit-line .el-select__inner {
  color: red;
  background-color: rgb(250 249 222);
}
::v-deep .el-input__icon.el-icon-date {
  width: 0;
  height: 0;
  overflow: hidden;
}
::v-deep .el-input__icon.el-icon-date:before {
  width: 0;
  height: 0;
}
::v-deep .el-input__icon.el-icon-time {
  width: 0;
  height: 0;
  overflow: hidden;
}
::v-deep .edit-line span {
  padding: 0 !important;
  vertical-align: middle;
}
.prompt-title {
  font-family: "黑体";
  font-size: 10px;
  white-space: pre;
}
</style>
